{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "77e2e5ad",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入余额:100\n",
      "------商品列表------\n",
      "0 蜜桃四季春 6元\n",
      "1 杨枝甘露 10元\n",
      "2 草莓摇摇奶昔 8元\n",
      "3 柠檬水 4元\n",
      "4 黄桃果霸 8元\n"
     ]
    }
   ],
   "source": [
    "# 1.运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给用户。\n",
    "good_list = [\n",
    "    [\"蜜桃四季春\",6],\n",
    "    [\"杨枝甘露\",10],\n",
    "    [\"草莓摇摇奶昔\",8],\n",
    "    [\"柠檬水\",4],\n",
    "    [\"黄桃果霸\",8],\n",
    "]\n",
    "# 数据存放，列表的增加（append）\n",
    "shopping_list = []\n",
    "\n",
    "\n",
    "AliPay = int(input(\"请输入余额:\"))\n",
    "while True:\n",
    "    print(\"------商品列表------\")\n",
    "    for i in range(5):\n",
    "        print(i,good_list[i][0],str(good_list[i][1])+\"元\")\n",
    "        #print(good_list[0][0],good_list[0][1])\n",
    "        #print(good_list[1][0],good_list[1][1])\n",
    "        #print(good_list[2][0],good_list[2][1])\n",
    "        #print(good_list[3][0],good_list[3][1])\n",
    "        #print(good_list[4][0],good_list[4][1])\n",
    "\n",
    "    user_choice = int(input(\"请输入商品编号:\"))\n",
    "    \n",
    "    if user_choice.isdigit() and int(user_choice)<len(good_list) and int(user_choice)>=0:\n",
    "        user_choice = int(user_choice)\n",
    "        if AliPay > good_list[user_choice][1]:\n",
    "            # 余额足够\n",
    "            AliPay = AliPay - good_list[user_choice][1] # 更新余额\n",
    "            shopping_list.append(good_list[user_choice])\n",
    "            print(\"下单成功，请10分钟后取餐......您的余额还有：%s元\"%(AliPay))\n",
    "        else:\n",
    "            # 余额不够\n",
    "            print(\"余额不足\"+str(good_list[user_choice][1])+\"元，请更换支付方式\")\n",
    "    \n",
    "    elif user_choice == \"Q\":\n",
    "        print(\"感谢您的购买，欢迎下次光临\")\n",
    "        print(\"您的购物车有\",shopping_list)\n",
    "        break\n",
    "    else:\n",
    "        print(\"你输入的商品不存在或您输入的内容有误\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d4a0e336",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
